#ifndef __AT_DEVICE_H
#define __AT_DEVICE_H

#include "bsp_uart.h"
#include "bsp_timer.h"

#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#ifdef RTOS

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
#include "semphr.h"
#include "event_groups.h"
#include "FreeRTOSConfig.h"

#endif


typedef enum
{
    CMD_AT = 0,  
	CMD_ATE0,  /*关闭回显*/  
   	CMD_IMEI,
   	CMD_ICCID,
	CMD_CSQ, /*信号强度RSSI*/
	CMD_URC, /*get urc data*/
	CMD_ADC, 
	CMD_NET,
	CMD_GMTTIME, 
	CMD_SENDDAT,
    CMD_DISABLE_PSM_MODE,
    CMD_DISABLE_SLEEP_MODE,
    CMD_PWR_OFF,
    CMD_AT_END,
}emATCommand;


typedef struct
{
	emATCommand	   CommandName;        //指令字符串名称
	char           *p_send;            //发送字符串指针
	uint16_t       wait_ack_dalay1ms;  //发送后查询返回指令最大响应时间，1ms为单位。
	uint8_t        max_try_times;      //最大重试次数
	uint8_t        max_reset_times;    //最大重启ATServer次数
}stcATConfig;


typedef enum AT_result
{
    Okay                          = 0u,  ///< OK
    Error_Response 			      = 1u,  ///< ATServer 回应ERROR
    Error_NoResponse              = 2u,  ///< 无回应
    Error_NotRecognized       	  = 3u,  ///< 无法识别的回应字符
    Error_NotReady                = 4u,  ///< AT server is Not Reday.
}emATResult;


/* AT Client 通用的属性*/
typedef struct
{   
	char imei[17]; // \r\n需要存储 
	char iccid[22];  
	char gmttime[26];  
	char ipport[20];  //平台IP+端口号+端口号
}stcATDev;

extern stcATDev ATdev;

emATResult ATClient_SendAT(void);
emATResult ATClient_Get_ICCID(void);
emATResult ATClient_Get_IMEI(void);
emATResult ATClient_Get_GMTtime(void);

emATResult ATClient_SetEchoOff(void);

emATResult ATClient_Set_DisablePSMMode(void);

emATResult ATClient_Connect_IOTPlatform(char *ip_port);


void ATClient_Init(void);


#endif
